package com.cci.kangdao.dao;

import com.cci.kangdao.dao.model.CustomerEngineRelT;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

//用户与发动机关系表类dao
public interface CustomerEngineRelTDao {

	/**
	 * 根据ESN获取发动机信息
	 * @param
	 * @return
	 */
	@Select("select * from CustomerEngineRel_T where ESN =  #{ESN}")
	public CustomerEngineRelT getEngineMsgByESN(Map<String, Object> map);

	//从CRM系统回馈的数据保存到用户与发动机关系表中
	public int insertCustomerEngineRelT(Map<String, Object> map);

	@Select("select a.ESN as esn,a.VIN as plateNumber,b.EsnPowerType as esnPowerType,b.EsnApplicationType as esnApplicationType," +
			"ISNULL(a.associationType,'') associationType  from CustomerEngineRel_T a\n" +
			"left join EngineMsg b on a.ESN = b.ESN\n" +
			"where a.UserId = #{userId} and a.Flag = 0")
	public List<Map<String, Object>> getEquipmentListByUserId(@Param("userId") Long userId);


	//获取所有用户已绑定的esn的信息
    @Select({"<script>" +
            "select distinct b.id,b.ESN from CustomerEngineRel_T a\n" +
            "inner join EngineMsg b on a.ESN = b.ESN \n" +
            "where a.Flag = 0" +
            " <if test='idStr!=null and idStr !=\"\" '>" +
            " and b.id in <foreach collection='idStr' item='item' open='(' separator=',' close=')'>#{item} </foreach> " +
            " </if>" +
            "</script>"
    })
    List<Map<String, Object>> getCustomerBindingESNList(@Param("idStr") List<String> idStr);

}
